<?php
namespace app\admin\validate;

class Menu extends \app\common\validate\Base {
	protected $rule=[
		'title|菜单标题'=>'length:2,32',
		'url|菜单访问路径'=>['regex'=>'/^[A-Z_a-z\/]+$/i'],
		'rules|菜单需求权限' => 'check_rule',
		'module_name|前端模块名'=>'check_module_name',
		'sort_order|菜单优先级' => 'number',
		'pid|父节点id' => 'check_id0:Menu',
	];

	protected $create_require=['title','rules','module_name','sort_order','pid'];

	protected function check_module_name($value,$data) {
		if (isset($data['pid']) && $data['pid']==0 && !$value)
			return '对于根节点，必须指定前端模块名称';
		return true;
	}

	protected function check_rule($value) {
		$m=model('Rule');
		if ($m->select($value))
			return true;
		else
			return "没有找到依赖规则";
	}
}
?>